<?php
$pathFile = __FILE__;
$dir = dirname($pathFile);
require_once 'config.php';
$configFile = APPLICATION_PATH . '/configs/' . SITE_NAME . 'application.ini';

if(!file_exists($configFile))
{
    die("Doesn't existed config file.");
}

$config = parse_ini_file($configFile, true);

if(empty($config["database : production"]) || !is_array($config["database : production"]))
{
    die("Doesn't existed settings for database");
}

$host = $config["database : production"]["database.params.host"];
$user = $config["database : production"]["database.params.username"];
$password = $config["database : production"]["database.params.password"];
$db = $config["database : production"]["database.params.dbname"];


class mySQL {

    protected $host;
    protected $user;
    protected $password;
    protected $db;
    protected $link;

    public function setHost($host)
    {
        $this->host = trim($host);
    }

    public function getHost()
    {
        return $this->host;
    }

    public function setUser($user)
    {
        $this->user = trim($user);
    }

    public function getUser()
    {
        return $this->user;
    }

    public function setPassword($password)
    {
        $this->password = trim($password);
    }

    public function getPassword()
    {
        return $this->password;
    }

    public function setDatabase($db)
    {
        $this->db = trim($db);
    }

    public function getDatabase()
    {
        return $this->db;
    }

    public function query($query)
    {
        if($this->link)
        {
            @mysql_query($query);
        }
    }

    public function connect()
    {
        $this->link = @mysql_connect($this->host, $this->user, $this->password);

        if(!$this->link)
        {
            throw new Exception('Could not connect: ' . mysql_error());
        }

        if(!@mysql_select_db($this->db))
        {
            throw new Exception("Unable to select $this->db: " . mysql_error());
        }
    }

    public function disconnect()
    {
        if($this->link)
        {
           @mysql_close($this->link);
        }
    }

}
try {
	echo "Working....";
    $mysql = new mySQL();
    $mysql->setHost($host);
    $mysql->setUser($user);
    $mysql->setPassword($password);
    $mysql->setDatabase($db);
    $mysql->connect();

	//QUERIES SECTION

	//22.07.2010 Alter for page table. Added: memlanding, is_prodcatland, is_prodbrandland fields
	$mysql->query("ALTER TABLE `page` ADD COLUMN `memlanding` ENUM('0','1') CHARSET utf8 COLLATE utf8_unicode_ci DEFAULT '0' NULL AFTER `protected`;");
	$mysql->query("ALTER TABLE `page` ADD COLUMN `is_prodcatland` ENUM('0','1') CHARSET utf8 COLLATE utf8_unicode_ci DEFAULT '0' NULL AFTER `memlanding`, ADD COLUMN `is_prodbrandland` ENUM('0','1') CHARSET utf8 COLLATE utf8_unicode_ci DEFAULT '0' NULL AFTER `is_prodcatland`;");
	//29.07.2010 Alter for shopping_quote table. Added: last_edited_by field
    $mysql->query("ALTER TABLE `shopping_quote`  ADD COLUMN `last_edited_by` VARCHAR(40) CHARSET utf8 COLLATE 'utf8_unicode_ci' NULL DEFAULT NULL AFTER `date`;");
	//30.07.2010 Alter for shopping_products table. Added: old_price field, sale_due
	$mysql->query("ALTER TABLE `shopping_products` ADD COLUMN `old_price` VARCHAR(25) CHARSET utf8 COLLATE utf8_unicode_ci NULL AFTER `page_id`;");
	$mysql->query("ALTER TABLE `shopping_products` ADD COLUMN `sale_due` DATE NULL AFTER `old_price`;");
    //01.09.2010 Alter for shopping_products table. Added: rating field
    $mysql->query("ALTER TABLE `shopping_products` ADD COLUMN `rating` VARCHAR(20) CHARSET utf8 NULL DEFAULT NULL AFTER `sale_due`;");
    //09.09.2010 New table shopping_products_review.
    $mysql->query("CREATE TABLE IF NOT EXISTS `shopping_products_review` (
          `id` int(10) unsigned NOT NULL AUTO_INCREMENT,
          `content` text COLLATE utf8_unicode_ci,
          `product_id` int(10) unsigned NOT NULL,
          `date` datetime DEFAULT NULL,
          `user_id` int(10) unsigned NOT NULL,
          `user_email` varchar(60) COLLATE utf8_unicode_ci DEFAULT '',
          `abuse` tinyint(1) DEFAULT '0',
          `user_name` varchar(50) COLLATE utf8_unicode_ci DEFAULT '',
          `user_website` varchar(50) COLLATE utf8_unicode_ci DEFAULT '',
          `topic` varchar(100) COLLATE utf8_unicode_ci DEFAULT '',
          `publish` tinyint(1) DEFAULT '1',
          `rank` tinyint(3) DEFAULT '0',
          `notify` tinyint(1) DEFAULT '0',
          PRIMARY KEY (`id`)
        ) ENGINE=InnoDB  DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci AUTO_INCREMENT=1 ;
    ");
    //15.09.2010 Update collation for field name from category table
    $mysql->query("ALTER TABLE `category`  CHANGE COLUMN `name` `name` VARCHAR(255) NULL DEFAULT NULL COLLATE 'utf8_unicode_ci' AFTER `id_parent`;");
    //17.09.2010 Update login and email fields length in user table
    $mysql->query("ALTER TABLE `user`  CHANGE COLUMN `login` `login` VARCHAR(255) NULL DEFAULT NULL COMMENT 'user login' COLLATE 'utf8_unicode_ci' AFTER `id_user_seosamba`,
        CHANGE COLUMN `email` `email` VARCHAR(255) NULL DEFAULT NULL COLLATE 'utf8_unicode_ci' AFTER `password`;");
    //01.10.2010 Alter shopping_quote table with adding 'valid_until' and 'discount' fields
    $mysql->query("ALTER TABLE `shopping_quote` ADD COLUMN `valid_until` TIMESTAMP NULL DEFAULT NULL  AFTER `last_edited_by` , ADD COLUMN `discount` MEDIUMINT UNSIGNED NULL DEFAULT 0  AFTER `valid_until`;");
    //05.10.2010 Alter table shopping_products with adding new field 'freebies'
    $mysql->query("ALTER TABLE `shopping_products` ADD COLUMN `freebies` VARCHAR(300) NULL DEFAULT ''  AFTER `rating` ;");
	//03.11.2010 Alter table forms. Added new 'track' field
	$mysql->query("ALTER TABLE `forms` ADD COLUMN `track` ENUM('0','1') DEFAULT '0' NOT NULL AFTER `useSMTP`;");
    //03.11.2010 Alter table forms. Added new 'tracking_data' field
	$mysql->query("ALTER TABLE `forms` ADD COLUMN `tracking_data` TEXT NULL AFTER `track`;");
	// 10.01.2011 Some toaster databases are missing 'cache' field in 'plugin' table
	$mysql->query("ALTER TABLE `plugin` ADD `cache` ENUM( '0', '1' ) CHARACTER SET utf8 COLLATE utf8_unicode_ci NOT NULL");
	//27.01.11 Added field 'raw_content' into the 'page' table.
	$mysql->query("ALTER TABLE `page` ADD COLUMN `raw_content` LONGTEXT NULL;");
	//10.02.11 Added index to the news table on `id_newscategory` field
	$mysql->query("ALTER TABLE `news` ADD INDEX `id_newscategory` (`id_newscategory`);");
	//23.05.11 Added 'mpn' (Manufacturer product number) to the 'shopping_product' table
	$mysql->query("ALTER TABLE `shopping_products` ADD COLUMN `mpn` VARCHAR(255) NULL AFTER `item_id`;");
	//26.05.11 Added 'short_description' field to the 'shopping_product' tabe
	//changed type of the 'desc' field from varchar to text with limit 10000
	$mysql->query("ALTER TABLE `shopping_products` ADD COLUMN `short_description` TEXT(400) NULL AFTER `brand`, CHANGE `desc` `desc` TEXT(10000) NULL");
	$mysql->query("ALTER TABLE `shopping_products` CHANGE `short_description` `full_description` TEXT(10000) CHARACTER SET utf8 COLLATE utf8_unicode_ci NULL , CHANGE `desc` `desc` TEXT(400) CHARACTER SET utf8 COLLATE utf8_unicode_ci NULL");
	//31.05.11 Added 'discount_tax_rate' field to the 'shopping_quote' table
	$mysql->query("ALTER TABLE  `shopping_quote` ADD  `discount_tax_rate` ENUM(  '0',  '1',  '2',  '3' ) NOT NULL DEFAULT  '1' AFTER  `discount`");
	//17.06.11 Fix for data type of 'discount' field in the 'shopping_quote' table
	$mysql->query("ALTER TABLE `shopping_quote` CHANGE `discount` `discount` DECIMAL( 10, 2 ) NULL DEFAULT '0' ");
    //25.07.11 Added `useConstantContact` and `constantContactList` fields to the table `forms`
    $mysql->query("ALTER TABLE `forms` ADD COLUMN `useConstantContact` enum('0','1') NULL DEFAULT '0' AFTER `tracking_data`");
	$mysql->query("ALTER TABLE `forms` ADD COLUMN `constantContactList` TEXT NULL AFTER `useConstantContact`");
 	$mysql->disconnect();
	echo "<br/>Done.";
}
catch (Exception $e)
{
    echo $e->getMessage();
}


?>
